{!!'<?php'!!}
namespace {{$namesPace}};
use App\Models\{{$config['modelName']}};
@foreach($methods as $method)
@if($method==='paginate')
use App\DTOS\Admin\{{$config['modelName']}}SearchDTO;
@elseif($method==='insert')
use App\DTOS\Admin\{{$config['modelName']}}InsertDTO;
@elseif($method==='updateById')
use App\DTOS\Admin\{{$config['modelName']}}UpdateDTO;
@endif
@endforeach
// {{$config['modelShowName']}}
class {{$className}}
{
    /**
    * @var \Illuminate\Database\Eloquent\Builder
    */
    private {{$config['modelName']}} $model;

    public function __construct()
    {
        $this->model = new {{$config['modelName']}};
        global $gameArea;
        $this->model->setGameArea($gameArea);
    }

@foreach($methods as $method)
@if($method==='paginate')
    public function {{$method}}({{$config['modelName']}}SearchDTO $DTO)
    {
        $perPage = $DTO->getLimit();
        $page = $DTO->getPage();
        $model = $this->model;
        /**条件判断**/
        return $model->orderByDesc("{{$config['orderByDesc']}}")->paginate($perPage,'*','page',$page);
    }

@elseif($method==='insert')
    /**
    * @param {{$config['modelName']}}InsertDTO $insertDTO
    * @return int
    */
    public function insert({{$config['modelName']}}InsertDTO $insertDTO){
        $data = $insertDTO->toArray();
        foreach($data as &$value){
            if (is_array($value)){
                $value= json_encode(array_values($value));
            }
        }
        $data['created_at'] = now();
        unset($data['page']); unset($data['limit']);
        return $this->model->insertGetId($data);
    }

@elseif($method==='updateById')
    /**
    * @param int $id
    * @param {{$config['modelName']}}UpdateDTO $updateDTO
    */
    public function updateById($id,{{$config['modelName']}}UpdateDTO $updateDTO)
    {
        $data = $updateDTO->toArray();
        foreach($data as &$value){
            if (is_array($value)){
                $value= json_encode(array_values($value));
            }
        }
        $data['updated_at'] = now();
        unset($data['page']); unset($data['limit']);
        $this->model->where('id',$id)->update($data);
    }

@elseif($method==='deleteById')
    public function deleteById($id)
    {
        $this->model->where('id',$id)->delete();
    }

@elseif($method==='deleteByIds')
    public function deleteByIds($ids)
    {
        if (empty($ids)) return;
        $this->model->whereIn('id',$ids)->delete();
    }
@elseif($method==='getById')
    public function {{$method}}($id)
    {
        return $this->model->where('id',$id)->first();
    }
@else
    public function {{$method}}()
    {
        return null;
    }

@endif
@endforeach
}
